package cn.itrip.trade.exception;


import cn.itrip.beans.dtos.Dto;
import cn.itrip.beans.dtos.InputDto;
import cn.itrip.beans.dtos.ResultCodeEnum;
import cn.itrip.common.ValidationToken;
import cn.itrip.trade.config.JwtUtil;
import cn.itrip.trade.config.StateException;
import io.jsonwebtoken.Claims;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:小伟
 * @Description:    判断token是否存在
 * @Date:2019-12-28 11:18
 **/
public class JwtInterceptor extends HandlerInterceptorAdapter {

    /**
     * preHandle方法是进行处理器拦截用的，顾名思义，该方法将在Controller处理之前进行调用。
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String authHeader = request.getHeader("token");
        System.out.println("-----"+authHeader);
        if (authHeader == null) {
            // 判断如果authHeader等于空 就会抛出异常 用户未登陆
            throw new StateException("21008","用户未登录,请先登陆","false");

        }
        return true;
    }
}





















